/**
 * @description 训练 router
 */
const router = require('koa-router')()
const { SuccessModel, ErrorModel } = require('../model/ResModel')
const { COURSE_LIST } = require('../constants/course')

router.prefix('/api/train')

/**
 * 获取训练课程列表
 */
router.get('/courseList', async (ctx, next) => {
  ctx.body = new SuccessModel(COURSE_LIST)
})

/**
 * 获取训练课程详情
 */
router.get('/courseDetail', async (ctx, next) => {
  const { id } = ctx.request.query
  const finded = COURSE_LIST.find(course => course.courseId === Number(id))

  if (finded === undefined) {
    ctx.body = new ErrorModel({
      errno: -1,
      message: '查找的课程不存在'
    })
  } else {
    ctx.body = new SuccessModel(finded)
  }
})


module.exports = router
